﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="chuyen_phong.aspx.cs" Inherits="App_Form_ktx_chuyen_phong" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .x-form-clear {
            background-image: url('../../resources/themes/images/default/form/search-trigger.gif');
            background-position: 0 0;
            width: 17px;
            height: 22px;
            border-bottom: 1px solid #b5b8c8;
            cursor: pointer;
            cursor: hand;
            overflow: hidden;
        }
    </style>
    <script type="text/javascript">

        Ext.require([
        'Ext.selection.CellModel',
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*',
        'Ext.grid.Panel'
        ]);

        Ext.onReady(function () {

            Ext.QuickTips.init();

            Ext.define('Ext.ux.CustomTrigger', {
                extend: 'Ext.form.field.Trigger',
                alias: 'widget.customtrigger',
                // override onTriggerClick
                initComponent: function () {
                    var me = this;

                    me.triggerCls = 'x-form-clear'; // native ExtJS class & icon

                    me.callParent(arguments);
                },
                onTriggerClick: function () {
                    //Mo cua so
                    var window = Ext.create('Ext.window.Window', {
                        title: 'Tìn kiếm thông tin sinh viên',
                        height: 350,
                        width: 400,
                        buttons: [
                            {
                                text: 'Chọn',
                                handler: function () {
                                    var records = Ext.getCmp("tm_sv").getSelectionModel().getSelection();
                                    if (records[0]) {
                                        var b_grid = records[0].get("sv_ma");
                                        Ext.getCmp("ma_sv").setValue(b_grid);
                                        window.close();
                                    }
                                }
                            }
                        ],
                        layout: {
                            type: 'table',
                            columns: 1
                        },
                        fieldDefaults: {
                            labelAlign: 'left',
                            msgTarget: 'side'
                        },
                        items: [
                           {
                               margin: '0 0 0 0',
                               xtype: 'fieldset',
                               title: 'Thông tin tim',
                               defaults: {
                                   width: 370,
                                   labelWidth: 90
                               },
                               defaultType: 'textfield',
                               items: [
                               {
                                   xtype: 'fieldcontainer',
                                   fieldLabel: 'Mã sinh viên',
                                   combineErrors: false,
                                   layout: {
                                       type: 'hbox',
                                       defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                   },
                                   defaults: {
                                       hideLabel: true
                                   },
                                   items: [
                                   { xtype: 'textfield', fieldLabel: 'sv_ma', width: 250, name: 'sv_ma', id: 'sv_ma', width: 140, allowBlank: true },
                                   {
                                       name: 'tim_kiem',
                                       xtype: 'button',
                                       width: 90,
                                       icon: '../../shared/icons/fam/refesh.png',
                                       text: 'Tìm',
                                       handler: function () {
                                           var b_ma = Ext.getCmp("sv_ma").getValue();
                                           DanhMuc.Fs_PHONG_DA_DK(b_ma, sinh_vien_tim_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                       }
                                   }
                                   ]
                               }]
                           },
                                {
                                    xtype: 'gridpanel',
                                    margin: '0 0 0 1',
                                    border: false,
                                    id: 'tm_sv',
                                    columns: [
                                        { id: 'svma', text: ' Mã SV', width: 50, flex: 1, sortable: true, dataIndex: 'sv_ma' },
                                        { id: 'svname', text: 'Tên sinh viên', width: 150, flex: 1, sortable: true, dataIndex: 'sv_ten' },
                                        { id: 'sv_lop', text: 'Lớp', width: 150, flex: 1, sortable: true, dataIndex: 'sv_lop' }
                                    ],
                                    store: null,
                                    listeners: {
                                        selectionchange: function (model, records) {

                                        }
                                    }
                                }]
                    }).show();
                }
            });

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel', {
                id: 'company-form',
                frame: true,
                bodyPadding: 5,
                layout: {
                    type: 'table',
                    columns: 1
                },
                fieldDefaults: {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items: [
                    {
                        margin: '0 0 5 5',
                        xtype: 'fieldset',
                        title: 'Thông tin tìm kiếm',
                        defaults: {
                            width: 600,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items: [
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                 {
                                     xtype: 'customtrigger',
                                     fieldLabel: 'Mã SV',
                                     id: 'ma_sv',
                                     name: 'ma_sv'
                                 },
                                {
                                    name: 'tim',
                                    xtype: 'button',
                                    width: 90,
                                    icon: '../../shared/icons/fam/refesh.png',
                                    text: 'Tìm kiếm',
                                    handler: function () {
                                        var b_masv = Ext.getCmp("ma_sv").getValue();
                                        if (b_masv == "") return alert("Chưa chọn sinh viên");
                                        DanhMuc.Fs_PHONG_DK_CT(b_masv, phong_dk_ct_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                    }
                                }
                            ]
                        }
                        ]
                    },
                    {
                        margin: '0 0 5 5',
                        xtype: 'fieldset',
                        title: 'Thông tin phòng ở',
                        defaults: {
                            width: 600,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items: [
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                 {
                                     xtype: 'displayfield', width: 80,
                                     fieldLabel: 'Tên SV'
                                 },
                                 { xtype: 'displayfield', value: '', id: 'tensv', width: 200 },
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Lớp'
                                 },
                                 { xtype: 'displayfield', value: '', id: 'lop', width: 200 }
                            ]
                        },
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Nhà'
                                 },
                                 { xtype: 'displayfield', value: '', id: 'nha', width: 200 },
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Phòng'
                                 },
                                 { xtype: 'displayfield', value: '', id: 'phong', width: 200 }
                            ]
                        },
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Giường'
                                 },
                                 { xtype: 'displayfield', value: '', id: 'sv_giuong', width: 200 }
                            ]
                        }
                        ]
                    },
                    {
                        margin: '0 0 5 5',
                        xtype: 'fieldset',
                        title: 'Thông tin phòng chuyển tới',
                        defaults: {
                            width: 600,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items: [

                             {
                                 xtype: 'fieldcontainer',
                                 combineErrors: true,
                                 layout: {
                                     type: 'hbox',
                                     defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                 },
                                 items: [
                                      {
                                          xtype: 'displayfield', width: 80, fieldLabel: 'Ngày chuyển'
                                      },
                                      {
                                          xtype: 'datefield', value: '', format: 'd/m/Y', name: 'ngay_chuyen',
                                          id: 'ngay_chuyen', width: 200, renderer: Ext.util.Format.dateRenderer('d/m/Y')
                                      },
                                      {
                                          xtype: 'hidden', width: 80, id: 'id_phong_cu'
                                      },
                                     { xtype: 'hidden', value: '', id: 'id_cu', width: 200 }
                                 ]
                             },
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                {
                                    xtype: 'displayfield', width: 80, fieldLabel: 'Nhà'
                                },
                                 {
                                     xtype: 'combo',
                                     width: 200,
                                     emptyText: 'Chọn tên nhà',
                                     triggerAction: 'all',
                                     forceSelection: true,
                                     editable: false,
                                     id: 'dm_nha',
                                     name: 'nha',
                                     displayField: 'tenNha',
                                     valueField: 'id',
                                     queryMode: 'local',
                                     store: null,
                                     listeners: {
                                         select: function (combo, record, index) {
                                             if (record.length > 0) {
                                                 var id_nha = record[0].get('id');
                                                 //Goi service
                                                 DanhMuc.Fs_PHONG_LKE(id_nha, phong_nha_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                             }
                                         }
                                     }
                                 },
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Phòng'
                                 },
                                 {
                                     xtype: 'combo',
                                     value: '',
                                     width: 200,
                                     emptyText: 'Chọn tên phòng',
                                     triggerAction: 'all',
                                     forceSelection: true,
                                     editable: false,
                                     id: 'chonphong',
                                     name: 'phong',
                                     displayField: 'Ten',
                                     valueField: 'id',
                                     queryMode: 'local',
                                     store: null,
                                     listeners: {
                                         select: function (combo, record, index) {
                                             if (record.length > 0) {
                                                 var id_nha = record[0].get('id');
                                                 //Goi service
                                                 DanhMuc.Fs_PHONG_CHUA_DK(id_nha, phong_dk_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                             }
                                         }
                                     }
                                 }
                            ]
                        },
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                 {
                                     xtype: 'displayfield', width: 80, fieldLabel: 'Giường'
                                 },
                                 {
                                     xtype: 'combo',
                                     value: '',
                                     width: 200,
                                     emptyText: 'Chọn tên giường',
                                     triggerAction: 'all',
                                     forceSelection: true,
                                     editable: false,
                                     id: 'chon_giuong',
                                     name: 'phong',
                                     displayField: 'Ten',
                                     valueField: 'id',
                                     queryMode: 'local',
                                     store: null
                                 }
                            ]
                        },
                         {
                             xtype: 'fieldcontainer',
                             combineErrors: true,
                             layout: {
                                 type: 'hbox',
                                 defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                             },
                             items: [
                                  {
                                      xtype: 'displayfield', width: 80, fieldLabel: 'Nội dung'
                                  },
                                  { xtype: 'textfield', value: '', name: 'ndung', id: 'ndung', width: 490 }
                             ]
                         }
                        ]
                    },
                    {
                        margin: '0 0 0 0',
                        xtype: 'fieldset',
                        title: '',
                        defaults: {
                            width: 600,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items: [
                        {
                            xtype: 'fieldcontainer',
                            padding: '7 0 0 130',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                {
                                    name: 'add',
                                    xtype: 'button',
                                    width: 90,
                                    icon: '../../shared/icons/fam/add.gif',
                                    text: 'Đồng ý',
                                    handler: function () {
                                        var form = this.up('form').getForm();
                                        if (form.isValid()) {
                                            var idphongcu = Ext.getCmp("id_phong_cu").getValue(),
                                           b_idcu = Ext.getCmp("id_cu").getValue(),
                                           idma_sv = Ext.getCmp("ma_sv").getValue(),
                                           idpm = Ext.getCmp("chonphong").getValue(),
                                           b_ngay = Ext.getCmp("ngay_chuyen").rawValue,
                                           b_idmoi = Ext.getCmp("chon_giuong").getValue(),
                                           idndung = Ext.getCmp("ndung").getValue();
                                            //
                                            if (b_ngay == "") return alert("Chưa chọn ngày");
                                            if (idpm == "") return alert("Chưa chọn phòng");
                                            if (b_idmoi == "") return alert("Chưa chọn giường");

                                            DanhMuc.Fs_PHONG_CHUYEN(b_idcu, idphongcu, b_idmoi, idpm, b_ngay, idma_sv, idndung, dang_kk_chuyen_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                }
                            ]
                        }
                        ]
                    }
                ],
                renderTo: bd
            });
            DanhMuc.Fs_NHA_LKE(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var a_kq = b_kq.split('@');
                var b_chuoi2 = CH_JSON(a_kq[0]);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'tenNha'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('dm_nha');
                c.bindStore(a_data2);
            }
        }
        function phong_dk_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'Ten'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('chon_giuong');
                c.bindStore(a_data2);
            }
        }
        function phong_nha_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'Ten'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('chonphong');
                c.bindStore(a_data2);
            }
        }
        function P_NHA_XOA_KQ(b_kq) {
            P_LOAD_TTCHUNG(b_kq);
            Ext.getCmp('id').setValue("");
        }
        function sinh_vien_tim_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ["sv_ma", "sv_ten", "sv_lop"],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('tm_sv');
                c.bindStore(a_data2);
            }
        }
        function phong_dk_ct_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                //tensv
                var b_chuoi2 = CH_JSON(b_kq);
                Ext.getCmp("tensv").setValue(b_chuoi2[0].ten_sv);
                Ext.getCmp("lop").setValue(b_chuoi2[0].ten_lop);
                Ext.getCmp("nha").setValue(b_chuoi2[0].tenNha);
                Ext.getCmp("phong").setValue(b_chuoi2[0].ten_phong);
                Ext.getCmp("sv_giuong").setValue(b_chuoi2[0].giuong);
                Ext.getCmp("id_phong_cu").setValue(b_chuoi2[0].idPhong);
                Ext.getCmp("id_cu").setValue(b_chuoi2[0].id);
            }
        }
        function dang_kk_chuyen_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
        }
    </script>
</asp:Content>

